package com.qunar.train.mock.dubbo;

import java.util.ArrayList;

public class WhiteList {

    public String ori;
    public String des;
    //白名单有顺序依赖，修改为ArrayList
    private static ArrayList<WhiteList> whitelist = new ArrayList<>();

    public WhiteList(String s1, String s2) {
        ori = s1;
        des = s2;
    }

    /**
     * type reFormat
     */
    static {
        whitelist.add(new WhiteList("[[B", "byte[][]"));
        whitelist.add(new WhiteList("[B", "byte[]"));
        whitelist.add(new WhiteList("[[I", "int[][]"));
        whitelist.add(new WhiteList("[I", "int[]"));
        whitelist.add(new WhiteList("$", "."));
        whitelist.add(new WhiteList("class ", ""));
        whitelist.add(new WhiteList("[L", ""));
        whitelist.add(new WhiteList("java.util.Map.java.util.Map", "java.util.Map"));
        whitelist.add(new WhiteList("interface ", ""));
        whitelist.add(new WhiteList(";", "[]"));
    }

    public static String typeFormat(String s) {
        for (int i = 0; i < whitelist.size(); i++) {
            WhiteList wl = whitelist.get(i);
            s = s.replace(wl.ori, wl.des);
        }
        return s;
    }
}
